<template>
  <div class="login-container">
    <div class="login-box">
      <el-switch v-model="theme" class="theme-change" width="60" inline-prompt active-value="dark"
                 inactive-value="light" active-text="🌞" inactive-text="🌛" @change="changeTheme" />
      <div class="login-left">
        <img src="@/assets/images/login_left.png" alt="login" />
      </div>
      <div class="login-form">
        <div class="login-logo">
          <img class="login-icon" src="@/assets/logo.png" alt="logo" />
          <span class="logo-text">从第一步开始……</span>
        </div>
        <!-- 显示不同组件 -->
        <LoginComponent v-if="loginType === 'login'" :loginFormData="loginFormData" :loading="loading" @changeLoginType="changeLoginType" />
        <RegisterComponent v-if="loginType === 'register'" :registerFormData="registerFormData" :loading="loading" @changeLoginType="changeLoginType" />
        <ForgotPasswordComponent v-if="loginType === 'forgotPassword'" :loading="loading" @changeLoginType="changeLoginType" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed } from 'vue'
// import { useUserStore } from '@/store/user'
import { useSystemStore } from '@/store/system'
// import { loginAdmin, sendCodeFunc, loginWithCode } from '@/api/login'
// import ElementPlus, { ElMessage } from 'element-plus'

import LoginComponent from '@/components/Login/Login.vue'
import RegisterComponent from '@/components/Login/Register.vue'
import ForgotPasswordComponent from '@/components/Login/ForgetPassword.vue'

import type { ILoginInf } from "@/interface/loginInf.ts";
import type { IRegisterInf } from "@/interface/registerInf.ts";

const loading = ref(false)
const loginType = ref('login')
const loginOrRegisterText = ref("登录")

const loginFormData: ILoginInf = reactive({
  email: '',
  password: '',
})
const registerFormData: IRegisterInf = reactive({
  email: '',
  password: '',
  againPassword: "",
  code: ""
})
// const userStore = useUserStore()
const systemStore = useSystemStore()

const theme = computed(() => systemStore.theme)

const changeTheme = (value: string) => {
  systemStore.changeTheme(value)
}

const changeLoginType = (type: "login" | "register" | "forgotPassword") => {
  loginType.value = type
  if (type === 'login') {
    loginOrRegisterText.value = '登录'
  } else if (type === 'register') {
    loginOrRegisterText.value = '注册'
  }
}
</script>

<style lang="scss" scoped>
/* 保持原样式不变 */
$bg: #23463e;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 550px;
  height: 100vh;
  min-height: 500px;
  background-image: url('@/assets/images/login_bg.svg');
  background-position: 50%;
  background-size: 100% 100%;
  background-size: cover;

  // background-color: $light_gray;
  input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px #293444 inset !important;
    -webkit-text-fill-color: #fff !important;
  }

  .el-input {
    // display: inline-block;
    height: 47px;
    flex: 1;

    :deep().el-input__wrapper {
      background-color: transparent;
      box-shadow: none;
    }

    :deep()input {
      border: 0;
      -webkit-appearance: none;
      border-radius: 0;
      padding: 12px 5px 12px 15px;
      height: 100%;
      font-size: 16px;
    }
  }

  .dark {
    position: absolute;
    top: 5%;
    right: 3.2%;
  }

  .login-box {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 96%;
    height: 94%;
    padding: 0 4% 0 20px;
    overflow: hidden;
    border-radius: 10px;

    position: relative;

    .theme-change {
      position: absolute;
      right: 20px;
      top: 0;
    }

    .login-left {
      width: 750px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .login-form {
      padding: 40px 45px 25px;
      border-radius: 10px;
      background-color: transparent !important;

      .login-form-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 10px 0 20px;
      }

      .login-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 40px;

        .login-icon {
          width: 100px;
        }

        .logo-text {
          padding-left: 25px;
          font-size: 48px;
          font-weight: bold;
          white-space: nowrap;
          background: linear-gradient(270deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8b00ff);
          background-clip: text;
          color: transparent;
        }
      }
    }
  }

  .iconfont {
    font-size: 30px;
  }
}
</style>
